﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using AMS.DataAccess.Sys.Interfaces;
using Spring.Context;
using Spring.Context.Support;
using AMS.DataAccess.Common;
using AMS.DataAccess.Sys.Filters;
using AMS.DataAccess.Sys.BO;
using AMS.DataAccess.Filter;

namespace AMS.Sys.WinForms
{
    public partial class FrmUsers : AMS.UI.Forms.BaseForm
    {
        public FrmUsers()
        {
            InitializeComponent();
            grid.Init("UserManager");
            ApplyDelayLoadData();
        }

        protected override void DelayLoadData()
        {
            Cursor = Cursors.WaitCursor;
            try
            {
                DoDataBind();
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }

        private void DoDataBind()
        {
            IApplicationContext context =  ContextRegistry.GetContext();
            IUserManager userMgr = (IUserManager)context.GetObject("UserManager");
            int totalRecordCount;
            List<UserInfo> users = userMgr.GetPagedUsers(Globals.Context, null , grid.CurrentPageIndex, grid.PageSize, out totalRecordCount);

            grid.DataBind(users);
            grid.RecordCount = totalRecordCount;
        }

        private void grid_PageIndexChanged(object sender, EventArgs e)
        {
            DoDataBind();
        }

        private void biAddUser_Click(object sender, EventArgs e)
        {
            new FrmEditUser().ShowDialog();
        }

    }
}
